package scala.day01

object Demo09Class {
  def main(args: Array[String]): Unit = {
    /**
      * 类和对象
      */
    val student = new Student(1,"zahngsan")
    println(student._name)
    println(student.getId())
    println(student)
    System.out.println(student)
    val liss = new Student(2,"liss",45)
    println(liss)

  }
  class Student(id: Int,name: String){
    println("默认构造函数")
    //定义属性并赋值
    //private属性私有化
    private val _id:Int = id
    val _name: String = name
    //下划线、占位符、没有实际意义，只是起到占位置的功能
    var _age: Int = _
    //定义方法
    def getId():Int = {
      return _id
    }

    override def toString: String = {
      "Student("+_id+","+_name+","+_age+")"
    }

    /**
      * 重载构造函数
      *
      * 在重载构造函数的第一行需要显示调用的默认构造参数
      */
    def this(id:Int,name:String,age:Int) {
      //调用默认构造参数
      this(id,name)
      //给属性复制
      this._age = age
    }
  }
}
